/**
 * @file 报表展示
 * @author caierwei(caierwei@baijia.com)
 * @date 2020-01-14
 */

import http from './http';
import constant from './constant';

/**
 * 报表展示 结果返回接口
 * API介绍地址：https://api.baijia.com/project/403/interface/api/287224
 * url: /api/transformation/values
 * 方法：POST
 *
 * @param  无参数
 * @return {Promise}
 */

export const getWindControlValues = params => http.post(constant.WIND_CONTROL.GET_WIND_CONTROL_VALUES, params);
export const fetchSearchFormOptions = params => http.post(constant.WIND_CONTROL.WIND_CONTROL_SELECT, params);
export const fetchDetail = params => http.post(constant.WIND_CONTROL.WIND_CONTROL_DETAIL, params);
// export const downLoad = params => http.post(constant.REPORTSCHART.TRANSFORM_DOWNLOAD, params);
export const downLoad = ({params, excelName = ''}) => http({
    url: constant.WIND_CONTROL.WIND_CONTROL_DOWNLOAD,
    method: 'post',
    data: {
        ...params
    },
    responseType: 'blob'
}).then(res => {
    const blob = new Blob([res], {
        type: 'application/vnd.ms-excel;'
    });
    const downloadElement = document.createElement('a');
    const href = window.URL.createObjectURL(blob);
    downloadElement.href = href;
    const time = (new Date()).getTime();
    downloadElement.download = `${excelName}${time}.xlsx`;
    // document.body.appendChild(downloadElement);
    downloadElement.click();
    // document.body.removeChild(downloadElement);
    // window.URL.revokeObjectURL(href);
});
